package com.kt.emall.ssoclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * @program: e-mall
 * @description: 首页
 * @author: KamTang
 * @create: 2022-01-15 18:49
 **/
@Controller
public class HelloController {

    @Value("${sso.server.url}")
    String url;

    /**
     *
     * @param model
     * @param session
     * @param token 第一次是没有携带token，所以需要修改required
     * @return
     */
    @GetMapping("/")
    public String index(Model model, HttpSession session, @RequestParam(value = "token", required = false) String token) {
        if (!StringUtils.isEmpty(token)) {

        }
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser == null) {
            return "redirect:" + url + "?redirect_url:http://client.com:8080";
        } else {
            ArrayList<String> emps = new ArrayList<>();
            emps.add("张三");
            emps.add("李四");
            model.addAttribute("emps", emps);
            return "index";
        }
    }
}
